package com.ctshk.sapp.booking.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.booking.dto.unsubscribe.get.SupplierUnsubscribeGetDTO;
import com.ctshk.rpc.booking.dto.unsubscribe.page.SupplierUnsubscribePageDTO;
import com.ctshk.rpc.booking.req.unsubscribe.page.SupplierUnsubscribePageReq;
import com.ctshk.rpc.booking.req.unsubscribe.save.SupplierUnsubscribeSaveReq;
import com.ctshk.rpc.booking.service.ISupplierUnsubscribeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 供应商退订 前端控制器
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-03-25
 */
@Api(value = "供应商预订-供应商退订管理", tags = "供应商预订-供应商退订管理")
@RestController
@RequestMapping("/supplier/unsubscribe")
public class SupplierUnsubscribeController extends BaseController {
    @DubboReference
    ISupplierUnsubscribeService supplierUnsubscribeService;

    @ApiOperation(value = "供应商预订-供应商退订-退订列表", notes = "供应商预订-供应商退订-退订列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SUPPLIER_BOOKING, operType = OperationLogType.QUERY, operTitle = "供应商预订-供应商退订-退订列表", operDesc = "供应商预订-供应商退订-退订列表")
    @PostMapping("/list")
    public Result<PageResponse<SupplierUnsubscribePageDTO>> getUnsubscribeList(@RequestBody SupplierUnsubscribePageReq supplierUnsubscribePageReq) {
        PageResponse<SupplierUnsubscribePageDTO> supplierOrderDTOPage = supplierUnsubscribeService.getUnsubscribeList(supplierUnsubscribePageReq);
        return Result.success(supplierOrderDTOPage);
    }

    @ApiOperation(value = "供应商预订-供应商退订-保存退订", notes = "供应商预订-供应商退订-保存退订")
    @OperationLogAnnotation(operModul = OperationLogModel.SUPPLIER_BOOKING, operType = OperationLogType.ADD, operTitle = "供应商预订-供应商退订-保存退订", operDesc = "供应商预订-供应商退订-保存退订")
    @PostMapping("/save")
    public Result<Long> saveUnsubscribe(@RequestBody @Valid SupplierUnsubscribeSaveReq supplierUnsubscribeSaveReq) {
        Long userId = getCurrentUser(getRequest()).getId();
        return supplierUnsubscribeService.saveUnsubscribe(supplierUnsubscribeSaveReq, userId);
    }

    @ApiOperation(value = "供应商预订-供应商退订-查询退订", notes = "供应商预订-供应商退订-查询退订")
    @OperationLogAnnotation(operModul = OperationLogModel.SUPPLIER_BOOKING, operType = OperationLogType.QUERY, operTitle = "供应商预订-供应商退订-查询退订", operDesc = "供应商预订-供应商退订-查询退订")
    @GetMapping("/{id}")
    public Result<SupplierUnsubscribeGetDTO> getUnsubscribe(@PathVariable("id") Long id) {
        SupplierUnsubscribeGetDTO supplierUnsubscribeGetDTO = supplierUnsubscribeService.getUnsubscribe(id);
        return Result.success(supplierUnsubscribeGetDTO);
    }
}
